package com.xzh.wms.config;

import com.xzh.wms.webselect.MyFilter;
import com.xzh.wms.webselect.MyListener;
import com.xzh.wms.webselect.MyServlet;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class WebServlet {

//    @Bean
    public ServletRegistrationBean servletRegistrationBean(){
        ServletRegistrationBean bean=new ServletRegistrationBean();
        bean.setServlet(new MyServlet());
        bean.addUrlMappings("/myServlet");
        return bean;
    }

//    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new MyFilter());
        bean.addUrlPatterns("/api/*");
        return bean;
    }

//    @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean(){
        ServletListenerRegistrationBean bean=new ServletListenerRegistrationBean();
        //注册监听器
        bean.setListener(new MyListener());
        //是否启用监听器
        bean.setEnabled(true);
        //监听器执行顺序
        bean.setOrder(3);
        return bean;
    }
}

